layui.define(['table', 'form', 'laypage', 'laydate', 'layer', 'carousel'], function (exports) {
        var $ = layui.$
            , table = layui.table
            , form = layui.form
            , laydate = layui.laydate
            , laypage = layui.laypage
            , layer = layui.layer
            , carousel = layui.carousel;

        //路径
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        var localhostPaht = curWwwPath.substring(0, pos);
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

        var limitcount = 10;
        table.render({
            elem: '#equipmentTable'
            , url: localhostPaht + projectName + "/rest/equipment/getListEquipment"
            , toolbar: '#equipmentOperation'
            , height: 'full-193'
            , title: '仪器设备检定信息表'
            , defaultToolbar: ['filter', 'print']
            , cols: [[{field: 'serialnumer', title: '序号', sort: true, rowspan: '2', width: 100},
                {field: 'stationnumber', title: '站内编号', sort: true, rowspan: '2', width: 150},
                {field: 'assetnumber', title: '资产编号', sort: true, rowspan: '2', width: 150},
                {field: 'equipmentname', title: '仪器设备名称', sort: true, rowspan: '2', width: 150},
                {field: 'model', title: '规格型号', sort: true, rowspan: '2', width: 150},
                {field: 'technicalindex', title: '主要技术指标', sort: true, rowspan: '2', width: 150},
                {field: 'factorynumber', title: '出厂编号', sort: true, rowspan: '2', width: 150},
                {field: 'place', title: '产地/厂商', sort: true, rowspan: '2', width: 150},
                {field: 'price', title: '价格(万)', sort: true, rowspan: '2', width: 150},
                {field: 'purchasedatestring', title: '购置日期', sort: true, rowspan: '2', width: 150},
                {field: 'storageroom', title: '存放房间', sort: true, rowspan: '2', width: 150},
                {field: 'responsible', title: '责任人', sort: true, rowspan: '2', width: 150},
                {field: 'status', title: '设备状况', sort: true, rowspan: '2', width: 150},
                {field: 'cycle', title: '检定周期', sort: true, rowspan: '2', width: 150},
                {field: 'verificationunit', title: '检定单位', sort: true, rowspan: '2', width: 150},
                {field: 'calibrationdatestring', title: '检定/校准有效日期', sort: true, rowspan: '2', width: 180},
                {field: 'sourcemode', title: '溯源方式', sort: true, rowspan: '2', width: 150},
                {field: 'calibration', title: '是否需要校准', sort: true, rowspan: '2', width: 150},
                {field: 'submissiondatestring', title: '计划检送日期', sort: true, rowspan: '2', width: 150},
                {field: 'responsibledep', title: '责任科室', sort: true, rowspan: '2', width: 150},
                {field: 'lackmaterial', title: '缺少资料', sort: true, rowspan: '2', width: 150},
                {field: 'reference', title: '档号', sort: true, rowspan: '2', width: 150},
                {field: 'completionstatus', title: '档案完成状态', sort: true, rowspan: '2', width: 150},
                {field: 'analysisproject', title: '分析项目', sort: true, rowspan: '2', width: 150},
                {field: 'type', title: '仪器类型', sort: true, rowspan: '2', width: 150},
                {field: 'calibrationcost', title: '检定/校准费用(元)', sort: true, rowspan: '2', width: 200},
                {field: 'computedvalue', title: '估算仪器维护、维修(元)', sort: true, rowspan: '2', width: 200},
                {field: 'computedvalues', title: '估算仪器维护、维修、耗材(元)', sort: true, rowspan: '2', width: 245},
                {field: 'maintenancecost', title: '每年维护费用', sort: true, rowspan: '2', width: 150},
                {align: 'center', title: '使用频率', colspan: '2'},
                {field: 'usagestatus', title: '使用状态', sort: true, rowspan: '2', width: 150},
                {field: 'exist', title: '仪器是否还存在', sort: true, rowspan: '2', width: 150},
                {field: 'alsoused', title: '将来是否还使用', sort: true, rowspan: '2', width: 150},
                {title: '操作', toolbar: '#table-equipment', align: "center", width: 250, fixed: "right"}],
                [
                    {field: 'eachs', title: '计时单位', sort: true, width: 150},
                    {field: 'usefrequency', title: '次数', sort: true, width: 100}
                ]]
            , page: false
            , limit: limitcount
            , text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            },
            // limits:[10, 20, 30, 40, 50],
            done: function (res, curr, count) {
                if (res.errorMsg == null) {

                } else {
                    layer.msg(res.errorMsg);
                }
                var curnum = $("#curnum").val();
                $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
                laypage.render({
                    elem: 'laypage'
                    , first: '首页'
                    , last: '尾页'
                    , groups: 5
                    , count: count
                    , curr: curnum
                    , limit: limitcount
                    , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                    , limits: [10, 15, 20]
                    , jump: function (obj, first) {
                        if (!first) {
                            curnum = obj.curr;
                            $("#curnum").val(curnum)
                            limitcount = obj.limit;
                            table.reload('equipmentTable', { //表格的id
                                where: {
                                    page: curnum,
                                    limit: limitcount
                                }
                            })

                        }
                    }
                })
            }
        })


        //监听工具条
        table.on('tool(equipmentTables)', function (obj) {  //表格的lay-filter="userlists"
            var data = obj.data; //获得当前行所有数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (obj.event === 'del') {
                deletes(data, obj);
            } else if (obj.event === 'update') {
                update(data);
            } else if (obj.event === 'info') {
                info(data)
            }else if(obj.event === 'overyears'){
                overyears(data)
            }
        });


        function deletes(data, obj) {
            layer.confirm('确定删除此数据', {icon: 3, title: '提示信息'}, function (index) {
                var index = layer.msg('删除中，请稍候', {icon: 16, time: false, shade: 0.6});
                setTimeout(function () {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "post",
                        url: localhostPaht + projectName + "/rest/equipment/deleteEquipment",
                        data: "tid=" + data.tid,
                        dataType: "json",
                        async: false,
                        success: function (msg) {
                            layer.close(index);
                            if (msg == true) {
                                layer.msg('删除成功');
                                obj.del();
                            } else {
                                layer.msg(msg.errorMsg);
                            }
                        }
                    })
                }, 2000);
            });
        }

        function update(data) {
            var clocess = "1";
            layer.open({
                title: "修改",
                type: 2,
                content: localhostPaht + projectName + '/rest/getRoute?type=instrument&url=equipment_update',
                //是否显示右上角关闭图标，默认为1，显示
                area: ['90%', '91%'],
                maxmin: true,
                shade: 0.6,
                anim: 4,
                skin: 'layui-layer-molv',
                resize: true,
                success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                    var iframe = window['layui-layer-iframe' + index];
                    iframe.child(data.tid)
                }, cancel: function (index, layero) {
                    layer.close(index)
                    clocess = "2"
                    return false;
                },
                end: function () {
                    if (clocess == "2") {

                    } else {
                        table.reload('equipmentTable')
                    }
                    return false;
                }
            });
        }

        function info(data) {
            layer.open({
                title: "详情",
                type: 2,
                content: localhostPaht + projectName + '/rest/getRoute?type=instrument&url=equipment_info',
                //是否显示右上角关闭图标，默认为1，显示
                area: ['90%', '91%'],
                maxmin: true,
                shade: 0.6,
                anim: 4,
                skin: 'layui-layer-molv',
                resize: true,
                success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                    var iframe = window['layui-layer-iframe' + index];
                    iframe.child(data.tid)
                }
            });
        }

    function overyears(data) {
        layer.open({
            title: "历年情况",
            type: 2,
            content: localhostPaht + projectName + '/rest/getRoute?type=instrument&url=overyears_list',
            //是否显示右上角关闭图标，默认为1，显示
            area: ['90%', '91%'],
            maxmin: true,
            shade: 0.6,
            anim: 4,
            skin: 'layui-layer-molv',
            resize: true,
            success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(data.tid)
            }
        });
    }

        exports('equipment', {})
    }
)
;